package com.leyou.item;

import com.leyou.LyItemApplication;
import com.leyou.item.dto.Ceshi;
import com.leyou.item.mapper.CeshiMapper;
import com.leyou.item.pojo.CeShi;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = LyItemApplication.class)
public class Demo1 {
    @Autowired
    private CeshiMapper ceshiMapper;
    @Test
    public void testDemo(){
        ArrayList<Ceshi> ceshis = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Ceshi ceshi = new Ceshi();
            ceshi.setName("lixiaou");
            ceshi.setAge(i);
            ceshis.add(ceshi);
        }
        ceshiMapper.insertList(ceshis);
    }
    @Test
    public void testDemo2(){
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        List<CeShi> ceShiList = ceshiMapper.queryList(list);
        for (CeShi ceShi : ceShiList) {

            System.out.println(ceShi);
        }
    }

    @Test
    public void testDemo3(){
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        //将集合拼接字符串, 注意StringUtils的包
        String namestr = StringUtils.join(list, ",");
        System.out.println(namestr);
        //查询时使用FIND_IN_SET替代foreach循环
        List<CeShi> ceShiList = ceshiMapper.queryList2(namestr);
        for (CeShi ceShi : ceShiList) {
            System.out.println(ceShi);
        }
    }
    @Test
    public void testDemo4(){
        //sql中测试&lt;&gt;(不等于)
        List<CeShi> list = ceshiMapper.select(3);
        for (CeShi ceShi : list) {
            System.out.println(ceShi);
        }
    }
}
